using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Security.Permissions;
using System.Globalization;

namespace Controls.Designer
{
    /// <summary>
    /// Provides custom designer support for <see cref="SequenceSplitter"/>.
    /// </summary>
    /// <author>Atanu Podder</author>
    /// <remarks>Currently this type does not add any custom designer support, can be 
    /// used to provide the same</remarks>
    [SupportsPreviewControl(true),
     SecurityPermission(SecurityAction.Demand,
     Flags = SecurityPermissionFlag.UnmanagedCode)]
    public class SequenceSplitterDesigner : ControlDesigner
    {
        /// <summary>
        /// Creates an instance of <see cref="SequenceSplitterDesigner"/>.
        /// </summary>
        public SequenceSplitterDesigner()
        {
        }

        /// <summary>
        /// Gets designer html for the <see cref="SequenceSplitter"/>.
        /// </summary>
        /// <returns>Designer html string.</returns>
        internal static string GetContainerDesignTimeHtml(IServiceProvider serviceProvider, string title, string subtitle, string content, string contentAttributes, bool isError)
        {
            string str = string.Empty;
            if (serviceProvider != null)
            {
                IResourceUrlGenerator service = (IResourceUrlGenerator)serviceProvider.GetService(typeof(IResourceUrlGenerator));
                if (service != null)
                {
                    str = string.Format(CultureInfo.InvariantCulture, "background-image:url({0});", 
                            new object[] { service.GetResourceUrl(typeof(ScriptManagerDesigner), 
                                            "System.Web.Resources.Design.Background.gif") });
                }
            }
            string str2 = isError ? string.Format(CultureInfo.InvariantCulture, 
                                    "<span style=\"color:red\">{0}</span>", new object[] { title }) : title;
            string str3 = !string.IsNullOrEmpty(subtitle) ? string.Format(CultureInfo.InvariantCulture, 
                                    " - {0}", new object[] { subtitle }) : string.Empty;
            string str4 = string.Empty;
            if (!string.IsNullOrEmpty(content) || !string.IsNullOrEmpty(contentAttributes))
            {
                str4 = string.Format(CultureInfo.InvariantCulture, "\r\n<tr>\r\n<td {1}>{0}</td>\r\n</tr>\r\n", new object[] { content, contentAttributes });
            }
            return string.Format(CultureInfo.InvariantCulture, "<table style=\"border:1px solid #CCCCCC;\" cellspacing=\"0\" cellpadding=\"0\">\r\n<tr>\r\n<td nowrap style=\"font:messagebox;background-color:#ffffff;color:#444444;{0}background-position:bottom;background-repeat:repeat-x;padding:4px;\"><strong>{1}</strong>{2}</td>\r\n</tr>{3}\r\n</table>", new object[] { str, str2, str3, str4 });
        }
 
        /// <summary>
        /// Passes through <see cref="SequenceSplitterDesigner.GetStandardDesignTimeHtml(IServiceProvider, string, string, string, string, bool)"/>.
        /// </summary>
        internal static string GetStandardDesignTimeHtml(IServiceProvider serviceProvider, string title, string subtitle, bool isError)
        {
            return GetContainerDesignTimeHtml(serviceProvider, title, subtitle, null, null, isError);
        }


        /// <summary>
        /// Passes through <see cref="SequenceSplitterDesigner.GetStandardDesignTimeHtml(IServiceProvider, string, string, bool)"/>.
        /// </summary>
        public override string GetDesignTimeHtml()
        {
            return GetStandardDesignTimeHtml(Component.Site, SequenceSplitter.GetType().Name, ID, false);
        }

        /// <summary>
        /// Gets associated <see cref="ComponentDesigner.Component"/> as <see cref="SequenceSplitter"/>.
        /// </summary>
        private SequenceSplitter SequenceSplitter
        {
            get
            {
                return (SequenceSplitter)Component;
            }
        }

    }
}